// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <memory>
#include <string_view>
#include <unordered_map>

#include <turbo/utility/status.h>
#include <turbo/base/macros.h>

namespace nebula::json::internal {

    /// This class is a helper to parse a json object from a string.
    /// It uses merak::json::Document in implementation.
    class TURBO_EXPORT ObjectParser {
    public:
        ObjectParser();

        ~ObjectParser();

        turbo::Status parse(std::string_view json);

        turbo::Result<std::string> get_string(const char *key) const;

        turbo::Result<bool> get_bool(const char *key) const;

        // Get all members of the object as a map from string keys to string values
        turbo::Result<std::unordered_map<std::string, std::string>> get_string_map() const;

    private:
        class Impl;

        std::unique_ptr<Impl> impl_;
    };

}  // namespace nebula::json::internal
